//
//  IpListReusableView.m
//  PeaPodAgent
//
//  Created by MasterLing on 2018/4/12.
//  Copyright © 2018年 MasterLing. All rights reserved.
//

#import "IpListReusableView.h"
#import "ProvinceModel.h"


@interface IpListReusableView()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@property (nonatomic, assign) CGAffineTransform originalTransform;

@end



@implementation IpListReusableView

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.originalTransform = self.iconImageView.transform;
    [self addActionWithblock:^{
        
        if (_provinceModel.isOpen) {
            // 逆时针旋转90° (关闭)
            _iconImageView.transform = CGAffineTransformRotate(_iconImageView.transform, -M_PI_2);
        } else {
            // 顺时针旋转90° (打开)
            _iconImageView.transform = CGAffineTransformRotate(_iconImageView.transform, M_PI_2);
        }
        
        _provinceModel.open = !_provinceModel.open;
        if (_delegate && [_delegate respondsToSelector:@selector(headerViewClicked:)]) {
            [_delegate headerViewClicked:self];
        }
    }];
}

- (void)setProvinceModel:(ProvinceModel *)provinceModel {
    _provinceModel = provinceModel;
    self.titleLabel.text = provinceModel.NAME;
    self.iconImageView.transform = self.originalTransform;
    if (_provinceModel.isOpen) {
        self.iconImageView.transform = CGAffineTransformRotate(self.iconImageView.transform, M_PI_2);
    }
}

@end
